﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReNameEx.Model
{
    public class ReplaceRule : ReExRuleBase
    {
        public override string GetDesc()
        {
            return $"替换所有 {SearchText} 为 {(string.IsNullOrEmpty(ReplaceText) ? "空文本" : ReplaceText)}";
        }

        public override void PrewRule(IEnumerable<ReExFile> files)
        {
            if (Enable)
            {
                foreach (ReExFile file in files)
                {
                    if (file.IsApply)
                    {
                        file.NewFileName = file.NewFileName.Replace(SearchText, ReplaceText, IgnoreCase, CultureInfo.InvariantCulture);
                    }
                }
            }
        }


        /// <summary>
        /// 删除模式 0全部文本 1文本匹配 2正则匹配 3分隔符
        /// </summary>
        public int SearchMode { get; set; } = 0;

        /// <summary>
        /// 匹配文本
        /// </summary>
        public string SearchText { get; set; } = string.Empty;
        /// <summary>
        /// 匹配文本
        /// </summary>
        public string ReplaceText { get; set; } = string.Empty;

    }
}
